<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Labourer extends Model
{
    use HasFactory;
    protected $fillable = [
        'name','avatar','mobile','sex','idcard','idcard_file','password',
        'post','work','bank','bank_number','type','province','city',
        'openid','ip','status','basic_salary',
        'start_date','end_date','remarks','project_id',
        'work_time','region'
    ];

    const POSTONLY = [
        'name','avatar','mobile','sex','idcard','idcard_file','password',
        'post','work','bank','bank_number','type','province','city',
        'openid','ip','status','basic_salary',
        'start_date','end_date','remarks','project_id',
        'work_time','region'
    ];

    protected $hidden = [
        'password',
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function attendance()
    {
        return $this->hasMany(LabourerAttendance::class,'labourer_id','id');
    }

    public function wage()
    {
        return $this->hasOne(LabourerWage::class,'labourer_id','id');
    }

    public function wages()
    {
        return $this->hasMany(LabourerWage::class,'labourer_id','id');
    }
}
